package com.md.model.word;

import com.md.model.base.ColorInfo;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STHexColor;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STThemeColor;

import java.util.Objects;

import static com.md.util.ColorUtil.convertToByteArray;
import static com.md.util.ColorUtil.getBlackColorInfo;

/**
 * @author 刘骄阳
 * 2024-05-14 18:58
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class WordColorInfo extends ColorInfo {

  public static WordColorInfo getColorInfo(final STHexColor stHexColor,
                                           final STThemeColor stThemeColor,
                                           final byte[] themeTint) {
    if (stHexColor == null && stThemeColor == null) {
      return null;
    }
    WordColorInfo colorInfo = new WordColorInfo();

    if (stHexColor != null) {
      colorInfo.setRgb((byte[]) stHexColor.getObjectValue());
      colorInfo.setRgb(convertToByteArray(stHexColor.getStringValue()));
    } else {
      // 说明直接设置的颜色
      colorInfo.setRgb(convertToByteArray(stThemeColor.getStringValue()));
    }
    return colorInfo;
  }

  public static WordColorInfo getColorInfo(final String color) {
    if (color == null) {
      return null;
    }
    if (Objects.equals(color, "auto")) {
      return getBlackColorInfo(WordColorInfo.class);
    }
    WordColorInfo colorInfo = new WordColorInfo();
    colorInfo.setRgb(convertToByteArray(color));
    return colorInfo;
  }

}
